<?php


use App\Library\Utils\Arr;
use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class HelpSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'CategorySeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $categories = $this->fetchAll('SELECT * FROM kg_category');
        $category = Arr::rand($categories);

        $titles = $this->getTitles();

        $rows = [];
        foreach ($titles as $title) {
            $rows[] = [
                'category_id' => $category['id'],
                'title' => $title,
                'content' => $faker->text(100),
                'priority' => rand(1, 5),
                'published' => 1,
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }
        $this->table('kg_help')->insert($rows)->saveData();
    }

    protected function getTitles()
    {
        return [
            '如何更换绑定的手机号，原有手机号不用了怎么办？',
            '课程可以退款吗？',
            '什么情况下我的账号会存在安全风险？',
            '如何注销账号？',
            '如果你被封号了？',
            '总是验证不通过，验证码控件异常？',
            '无法接收短信验证码？',
            '为什么用电脑访问时视频无法播放？',
        ];
    }
}
